home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1014 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: EU.net!sun4nl!news
  3. From: vdkamp@inter.nl.net (Peter H.J. van der Kamp)
  4. Subject: Problem with SEEKG
  5. X-Nntp-Posting-Host: asp99-21.amsterdam.nl.net
  6. Content-Type: Text/Plain; charset=US-ASCII
  7. Message-ID: <DKvpAn.MB6@inter.NL.net>
  8. Sender: news@inter.NL.net (News at news)
  9. Organization: VDK
  10. X-Newsreader: WinVN 0.99.6
  11. Mime-Version: 1.0
  12. Date: Mon, 8 Jan 1996 20:08:47 GMT
  13.  
  14. Hello all,
  15.  
  16. I have problems with seekg. In my program I have two functions: one reads a 
  17. file sequential, the other reads the file random.
  18. Code for function one:
  19.  char *stationsfile = "d:\\stations.dat";
  20.  stations.open(stationsfile, ios::in);
  21.  stations.getline(record,recordlengte);
  22.  while (!stations.eof())
  23.  { ....
  24.    stations.getline(record,recordlengte);
  25.  }
  26.  stations.close();
  27.  stations.clear(ios::goodbit);
  28.  
  29. This works fine.
  30.  
  31. Code for function two:
  32.  char *stationsfile = "d:\\stations.dat";
  33.  stations.open(stationsfile, ios::in | ios::binary);
  34.  stations.seekg(0, ios::end);
  35.  
  36. Via the debugger I can see that the file is opened correctly, but I get an 
  37. GPF on seekg.
  38. I tried the following:
  39.  seekg(1);
  40.  seekg(1, ios::beg);
  41.  seekg(-1, ios::end);
  42. but that didn't solve the GPF. According to my C++ books this code ought to 
  43. be right, but at the moment I'm not such an experienced C++ programmer, so 
  44. what do I wrong?
  45. Environment: DOS 6.0, Windows 3.1, Borland Turbo C++ for Windows 3.1. 
  46.  
  47. --Peter van der Kamp
  48.  
  49.